package cn.car91.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import cn.car91.R;

public class TechnologyListAdapter extends BaseAdapter {

    private List<String> data;

    public List<String> getData() {
        return data;
    }

    public void setData(List<String> data) {
        this.data = data;
    }

    public void addData(List<String> data) {
        this.data.addAll(data);
    }

    private LayoutInflater layoutInflater;
    private Context context;

    public TechnologyListAdapter(Context context) {
        this.context = context;
        this.layoutInflater = LayoutInflater.from(context);
        this.data = new ArrayList<String>();
    }

    public final class TechnologyItem {
        public TextView name;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int arg0) {
        // TODO Auto-generated method stub
        return data.get(arg0);
    }

    @Override
    public long getItemId(int arg0) {
        // TODO Auto-generated method stub
        return arg0;
    }

    @Override
    public View getView(int arg0, View arg1, ViewGroup arg2) {
        // TODO Auto-generated method stub
        TechnologyItem technologyItem = null;
        if (arg1 == null) {
            technologyItem = new TechnologyItem();

            arg1 = layoutInflater.inflate(R.layout.view_tech_ware_item, null);
            technologyItem.name = (TextView) arg1;
            arg1.setTag(technologyItem);
        } else {
            technologyItem = (TechnologyItem) arg1.getTag();
        }
        technologyItem.name.setText(data.get(arg0));
        return arg1;
    }

}
